﻿using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace Editor.Utilities
{
    public static class ImageWorker
    {
        public static byte[] GetByteArray(Image image)
        {
            if (image == null) 
                return null;

            using (MemoryStream ms = new MemoryStream())
            {
                image.Save(ms, ImageFormat.Png);
                return ms.ToArray();
            }
        }

        public static Image GetImage(byte[] serialized)
        {
            if (serialized == null) 
                return null;

            using (MemoryStream ms = new MemoryStream(serialized))
            {
                return new Bitmap(ms);
            }
        }
    }
}
